// string.hpp
// An encapsulation of a char* C string. Also an implementation of a growing
// C string buffer.
//
// Copyright (C) 2008  Maksim Sipos <msipos@mailc.net>
//
// This file is a part of the Ripe language project.
//
// Ripe is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef R_STRING_HPP
#define R_STRING_HPP

#include "standard.hpp"

namespace Ripe {
  class String {
    public:
      // Empty string.
      String();

      // Construct from a C string.
      String(char* s);
      
      // Copy constructor.
      String(const String& other);

      // Assignment copy constructor.
      String& operator= (const String& other);

      // Assignment from a C string.
      String& operator= (const char* s);

      // Unallocate c_str (if not NULL)
      ~String();

      // Format the string in a 2Kb buffer.
      void format(const char* fmt, ...);

      // Underlying C string (may be NULL if string is empty).
      char* c_str;
  };

  class StringBuffer {
    public:
      // Construct a buffer:
      StringBuffer(uint32_t n = 0);

      uint32_t size;

      char* buf;

      // Expand to accomodate at least new_size bytes.
      void ensure(uint32_t new_size);
      
      // Unallocate the buffer:
      ~StringBuffer();
  };
}

#endif // R_STRING_HPP
